/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GamePlayFrame.java
 *
 * Created on 2009/05/31, 13:05:30
 */
package org.sais.eswn.ui;

import org.sais.eswn.core.GameCore;
import org.sais.eswn.core.IGameInterface;
import org.sais.eswn.core.Player;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JList;
import javax.swing.border.TitledBorder;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.Document;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import org.sais.eswn.card.Card;
import org.sais.eswn.card.CardSet;
import org.sais.eswn.card.cardlabel.ICardLabelCallback;
import org.sais.eswn.card.cardlabel.UniLabel;
import org.sais.eswn.deck.Deck;
import org.sais.eswn.deck.DeckEditorWindow;
import org.sais.eswn.tool.MyListModel;
import org.sais.eswn.tool.Tools;

/**
 *
 * @author Romulus
 */
public class GamePlayFrame extends javax.swing.JFrame implements IGameInterface, ICardLabelCallback, ActionListener {

    private GameCore mCore;
    private SwingUpdater mSwingUpdater;

    public GamePlayFrame(GameCore core) {
        initComponents();
        mCore = core;
        init();
        this.setVisible(true);
    }

    private void init() {
        mSwingUpdater = new SwingUpdater(this);
        if (mCore.isWatcher()) {
            _gamemenu.setEnabled(false);
        }
    }

    private void loadDeck() {
        mCore.loadDeck(Player.ICH);
    }

    private void openDeckEditor() {
        try {
            new DeckEditorWindow("alpha");
        } catch (Exception ex) {
            Logger.getLogger(GamePlayFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    private void showRegion(final int region, CardSet cards) {
        UpdateTask u = new UpdateTask(UpdateTask.TaskList.showRegion);
        u.addParameter(new Integer(region));
        u.addParameter(cards);
        mSwingUpdater.add(u);
    }

    public void swing_showRegion(final int region, ArrayList<Card> cards) {
        MyListModel mod = new MyListModel();
        JList list = null;
        mod.removeAllElements();

        switch (region) {
            case GameCore.REGION_DECK:
                list = _mydeck;
                break;
            case GameCore.REGION_FIELD:
                list = _myfield;
                break;
            case GameCore.REGION_PLAY_SPELL:
                list = _myplayspell;
                break;
            case GameCore.REGION_PLAY_EVENT:
                list = _myplayevent;
                break;
            case GameCore.REGION_GRAVE:
                list = _mygrave;
                break;
            case GameCore.REGION_OPP_DECK:
                list = _oppdeck;
                break;
            case GameCore.REGION_OPP_FIELD:
                list = _oppfield;
                break;
            case GameCore.REGION_OPP_GRAVE:
                list = _oppgrave;
                break;
            default:
                assert false;
        }

        list.setModel(mod);
        list.setCellRenderer(new MyCellRenderer());
        ListSelectionListener[] listeners = list.getListSelectionListeners();
        for (int k = 0; k <
                listeners.length; ++k) {
            list.removeListSelectionListener(listeners[k]);
        }

        for (Card c : cards) {
            mod.addElementwithoutFire(new ListItem(c.getDisplayColor(), c.name, new UniLabel(this, c.no, region, mCore.isWatcher())));
        }
        mod.fire();

        final JList jlist = list;

        if (list.getToolTipText() == null) {
            list.addMouseListener(new java.awt.event.MouseAdapter() {

                @Override
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    int index = jlist.locationToIndex(evt.getPoint());
                    if (index < 0) {
                        return;
                    }
                    jlist.setSelectedIndex(index);
                    showCard(((ListItem) (jlist.getModel().getElementAt(index))).label.cardno);
                    if (mCore.isWatcher()) {
                        return;
                    }
                    try {
                        if (evt.getButton() != MouseEvent.BUTTON1 || evt.isControlDown()) {
                            onCardClicked((JList) evt.getSource(), evt);
                        }

                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            });

            list.addKeyListener(new KeyListener() {

                public void keyTyped(KeyEvent e) {
                }

                public void keyPressed(KeyEvent e) {
                }

                public void keyReleased(KeyEvent e) {
                    if (e.getKeyCode() == KeyEvent.VK_DOWN || e.getKeyCode() == KeyEvent.VK_UP) {
                        showCard(((ListItem) (jlist.getModel().getElementAt(jlist.getSelectedIndex()))).label.cardno);
                    }
                }
            });
        }

        list.setToolTipText("");
    }

    /**
     * Apply a right click (or control masked click) on card label. Implemented methods are:
     * in Deck: Single click to play; Shift masked click to graveyard.
     * in Play: Cancel playing.
     * in Field: Single click to graveyard; Shift masked click to deck.
     * in Graveyard: Single click to hand; Shift masked click to field.
     * @param list
     * @param evt
     */
    private void onCardClicked(JList list, MouseEvent evt) {
        if (list == _mydeck) {
            ListItem item = (ListItem) list.getSelectedValue();
            if (evt.isShiftDown()) {
                mCore.move(GameCore.REGION_DECK, GameCore.REGION_GRAVE, item.label.cardno, Player.ICH);
                update(Player.ICH);
            } else {
                if (mCore.getPhase() != GameCore.PHASE_TACTICS) {
                    return;
                }
                CardSet set = new CardSet();
                set.add(Tools.getCard(item.label.cardno));
                if (item.label.getInfo().getType() == Card.CARDTYPE_SPELL) {
                    showRegion(GameCore.REGION_PLAY_SPELL, set);
                } else {
                    // EVENT
                    showRegion(GameCore.REGION_PLAY_EVENT, set);
                }
            }
        } else if (list == _myplayspell) {
            if (mCore.getPhase() != GameCore.PHASE_TACTICS) {
                return;
            }
            showRegion(GameCore.REGION_PLAY_SPELL, CardSet.emptySet());
        } else if (list == _myplayevent) {
            if (mCore.getPhase() != GameCore.PHASE_TACTICS) {
                return;
            }
            showRegion(GameCore.REGION_PLAY_EVENT, CardSet.emptySet());
        } else if (list == _myfield) {
            ListItem item = (ListItem) list.getSelectedValue();
            if (evt.isShiftDown()) {
                mCore.move(GameCore.REGION_FIELD, GameCore.REGION_DECK, item.label.cardno, Player.ICH);
            } else {
                mCore.move(GameCore.REGION_FIELD, GameCore.REGION_GRAVE, item.label.cardno, Player.ICH);
            }
            update(Player.ICH);
        } else if (list == _mygrave) {
            ListItem item = (ListItem) list.getSelectedValue();
            if (evt.isShiftDown()) {
                mCore.move(GameCore.REGION_GRAVE, GameCore.REGION_DECK, item.label.cardno, Player.ICH);
            } else {
                mCore.move(GameCore.REGION_GRAVE, GameCore.REGION_FIELD, item.label.cardno, Player.ICH);
            }
            update(Player.ICH);
        }
    }

    /**
     * Put cards set to play into the field
     */
    public void play(int playerIndex) {
        switch (mCore.getPhase()) {
            case GameCore.PHASE_TACTICS:
                if (_myplayspell.getModel().getSize() > 0) {
                    ListItem item = (ListItem) _myplayspell.getModel().getElementAt(0);
                    mCore.move(GameCore.REGION_DECK, GameCore.REGION_FIELD, item.label.cardno, playerIndex);
                }
                if (_myplayevent.getModel().getSize() > 0) {
                    ListItem item = (ListItem) _myplayevent.getModel().getElementAt(0);
                    mCore.move(GameCore.REGION_DECK, GameCore.REGION_FIELD, item.label.cardno, playerIndex);
                }
                mCore.nextPhase();
                update(playerIndex);
                insertMessage(Tools.getLoc(24), Color.BLACK);
                break;
            case GameCore.PHASE_BATTLE:
                ArrayList<Card> moving = new ArrayList<Card>();
                for (Object o : mCore.getField(playerIndex)) {
                    Card c = (Card) o;
                    if (c.getType() == Card.CARDTYPE_EVENT) {
                        moving.add(c);
                    }
                }
                for (Card c : moving) {
                    mCore.move(GameCore.REGION_FIELD, GameCore.REGION_GRAVE, c.no, playerIndex);
                }
                mCore.nextPhase();
                update(playerIndex);
                insertMessage(Tools.getLoc(25), Color.BLACK);
                break;
        }
    }

    private void setPlay() {
        mCore.setPlay(Player.ICH, true);
    }

    public void update(int playerIndex) {
        if (playerIndex == Player.ICH) {
            showRegion(GameCore.REGION_DECK, mCore.getRemainingDeck(playerIndex));
            showRegion(GameCore.REGION_FIELD, mCore.getField(playerIndex));
            showRegion(GameCore.REGION_GRAVE, mCore.getGrave(playerIndex));
            showRegion(GameCore.REGION_PLAY_SPELL, CardSet.emptySet());
            showRegion(GameCore.REGION_PLAY_EVENT, CardSet.emptySet());
        } else {
            showRegion(GameCore.REGION_OPP_DECK, mCore.getRemainingDeck(playerIndex));
            showRegion(GameCore.REGION_OPP_FIELD, mCore.getField(playerIndex));
            showRegion(GameCore.REGION_OPP_GRAVE, mCore.getGrave(playerIndex));
        }
        _phase.setText(mCore.getPhase() == GameCore.PHASE_TACTICS ? Tools.getLoc(19) : Tools.getLoc(20));
    }

    @Override
    public void setPlayerName(int playerIndex, String name) {
        if (playerIndex == Player.ICH) {
            ((TitledBorder) _mydeck.getBorder()).setTitle(name + "：" + mCore.getPlayer(playerIndex).getDeckName());
        } else {
            ((TitledBorder) _oppdeck.getBorder()).setTitle(name + "：" + mCore.getPlayer(playerIndex).getDeckName());
        }
    }

    public void setDeck(int playerIndex, String playerName, Deck deck) {
        _myfield.removeAll();
        _mygrave.removeAll();
        _mydeck.removeAll();
        _myplayspell.removeAll();
        _myplayevent.removeAll();
        _oppfield.removeAll();
        _oppgrave.removeAll();
        _oppdeck.removeAll();
        update(playerIndex);

        TitledBorder border;
        int region;
        if (playerIndex == Player.ICH) {
            border = ((TitledBorder) _mydeck.getBorder());
            region = GameCore.REGION_DECK;
        } else {
            border = ((TitledBorder) _oppdeck.getBorder());
            region = GameCore.REGION_OPP_DECK;
        }

        CardSet cards = new CardSet(deck.listCardnos());
        border.setTitle(playerName + "：" + deck.getDeckname());

        showRegion(region, cards);

    }

    public void showCard(String cardno) {
        Tools.showCard(cardno, _SCArea);
    }

    public void setCusTitle(String title) {
        setTitle(title);
    }

    public void actionPerformed(ActionEvent e) {
        if (mSwingUpdater == null) {
            return;
        }

        UpdateTask task = mSwingUpdater.pop();
        if (task == null) {
            return;
        }

        switch (task.task) {
            case showRegion:
                swing_showRegion((Integer) task.parameters.get(0), (CardSet) task.parameters.get(1));
                break;
        }

    }

    public void insertMessage(String message, Color color) {
        try {
            SimpleAttributeSet set = new SimpleAttributeSet();
            Document doc = _messagebox.getStyledDocument();
            StyleConstants.setForeground(set, color);
            doc.insertString(doc.getLength(), message + '\n', set);
            _messagebox.setCaretPosition(_messagebox.getDocument().getLength() - 1);
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    private void sendChat() {
        if (_chatbox.getText().length() > 0) {
            if (mCore.isWatcher()) {
                insertMessage(mCore.getPlayer(Player.ICH).getName() + ": " + _chatbox.getText(), new Color(120, 60, 0));
                mCore.send("$CHAT:" + mCore.getSock().getPlayerName() + ": " + _chatbox.getText());
            } else {
                insertMessage(mCore.getPlayer(Player.ICH).getName() + ": " + _chatbox.getText(), Color.BLUE);
                mCore.send("$CHAT:" + mCore.getPlayer(Player.ICH).getName() + ": " + _chatbox.getText());
            }
            _chatbox.setText("");
        }
    }

    public void send(String message) {
        mCore.send(message);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        _scroll_oppdeck = new javax.swing.JScrollPane();
        _oppdeck = new javax.swing.JList();
        _scroll_mydeck = new javax.swing.JScrollPane();
        _mydeck = new javax.swing.JList();
        _myfieldpanel = new javax.swing.JPanel();
        _scroll_mydeck1 = new javax.swing.JScrollPane();
        _myfield = new javax.swing.JList();
        jScrollPane2 = new javax.swing.JScrollPane();
        _myplayspell = new javax.swing.JList();
        jScrollPane3 = new javax.swing.JScrollPane();
        _myplayevent = new javax.swing.JList();
        _play = new javax.swing.JButton();
        _phase = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        _SCArea = new javax.swing.JTextPane();
        jScrollPane4 = new javax.swing.JScrollPane();
        _mygrave = new javax.swing.JList();
        jScrollPane5 = new javax.swing.JScrollPane();
        _oppgrave = new javax.swing.JList();
        _oppfieldpanel = new javax.swing.JPanel();
        _scroll_mydeck2 = new javax.swing.JScrollPane();
        _oppfield = new javax.swing.JList();
        _chatpanel = new javax.swing.JPanel();
        _chatbox = new javax.swing.JTextField();
        _sendchat = new javax.swing.JButton();
        jScrollPane6 = new javax.swing.JScrollPane();
        _messagebox = new javax.swing.JTextPane();
        jMenuBar1 = new javax.swing.JMenuBar();
        _gamemenu = new javax.swing.JMenu();
        _loaddeck = new javax.swing.JMenuItem();
        _opendeckeditor = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        _checkrule = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sais/eswn/ui/Bundle"); // NOI18N
        setTitle(bundle.getString("GamePlayFrame.title")); // NOI18N

        _oppdeck.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("GamePlayFrame._oppdeck.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("MS PGothic", 0, 12))); // NOI18N
        _oppdeck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        _scroll_oppdeck.setViewportView(_oppdeck);

        _mydeck.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("GamePlayFrame._mydeck.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("MS PGothic", 0, 12))); // NOI18N
        _mydeck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        _scroll_mydeck.setViewportView(_mydeck);

        _myfieldpanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        _myfield.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("GamePlayFrame._myfield.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("ＭＳ Ｐゴシック", 0, 12))); // NOI18N
        _myfield.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        _scroll_mydeck1.setViewportView(_myfield);

        jScrollPane2.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane2.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        _myplayspell.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("GamePlayFrame._myplayspell.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("ＭＳ Ｐゴシック", 0, 12))); // NOI18N
        _myplayspell.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        jScrollPane2.setViewportView(_myplayspell);

        jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        jScrollPane3.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);

        _myplayevent.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("GamePlayFrame._myplayevent.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("ＭＳ Ｐゴシック", 0, 12))); // NOI18N
        _myplayevent.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        jScrollPane3.setViewportView(_myplayevent);

        _play.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        _play.setText(bundle.getString("GamePlayFrame._play.text")); // NOI18N
        _play.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _playActionPerformed(evt);
            }
        });

        _phase.setFont(new java.awt.Font("MS PGothic", 0, 12));
        _phase.setText(bundle.getString("GamePlayFrame._phase.text")); // NOI18N

        javax.swing.GroupLayout _myfieldpanelLayout = new javax.swing.GroupLayout(_myfieldpanel);
        _myfieldpanel.setLayout(_myfieldpanelLayout);
        _myfieldpanelLayout.setHorizontalGroup(
            _myfieldpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(_scroll_mydeck1, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
            .addGroup(_myfieldpanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(_phase)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 92, Short.MAX_VALUE)
                .addComponent(_play)
                .addContainerGap())
        );
        _myfieldpanelLayout.setVerticalGroup(
            _myfieldpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(_myfieldpanelLayout.createSequentialGroup()
                .addComponent(_scroll_mydeck1, javax.swing.GroupLayout.PREFERRED_SIZE, 126, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(_myfieldpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_phase)
                    .addComponent(_play))
                .addContainerGap())
        );

        _SCArea.setContentType(bundle.getString("GamePlayFrame._SCArea.contentType")); // NOI18N
        _SCArea.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        jScrollPane1.setViewportView(_SCArea);

        _mygrave.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("GamePlayFrame._mygrave.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("MS PGothic", 0, 12))); // NOI18N
        _mygrave.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12)); // NOI18N
        jScrollPane4.setViewportView(_mygrave);

        _oppgrave.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("GamePlayFrame._oppgrave.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("MS PGothic", 0, 12))); // NOI18N
        _oppgrave.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12)); // NOI18N
        jScrollPane5.setViewportView(_oppgrave);

        _oppfieldpanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        _oppfield.setBorder(javax.swing.BorderFactory.createTitledBorder(null, bundle.getString("GamePlayFrame._oppfield.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("ＭＳ Ｐゴシック", 0, 12))); // NOI18N
        _oppfield.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        _scroll_mydeck2.setViewportView(_oppfield);

        javax.swing.GroupLayout _oppfieldpanelLayout = new javax.swing.GroupLayout(_oppfieldpanel);
        _oppfieldpanel.setLayout(_oppfieldpanelLayout);
        _oppfieldpanelLayout.setHorizontalGroup(
            _oppfieldpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(_scroll_mydeck2, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
        );
        _oppfieldpanelLayout.setVerticalGroup(
            _oppfieldpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(_scroll_mydeck2, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
        );

        _chatpanel.setPreferredSize(new java.awt.Dimension(580, 90));

        _chatbox.setFont(new java.awt.Font("ＭＳ Ｐ明朝", 0, 12));
        _chatbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _chatboxActionPerformed(evt);
            }
        });

        _sendchat.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        _sendchat.setText(bundle.getString("GamePlayFrame._sendchat.text")); // NOI18N
        _sendchat.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _sendchatActionPerformed(evt);
            }
        });

        _messagebox.setFont(new java.awt.Font("ＭＳ Ｐ明朝", 0, 12));
        jScrollPane6.setViewportView(_messagebox);

        javax.swing.GroupLayout _chatpanelLayout = new javax.swing.GroupLayout(_chatpanel);
        _chatpanel.setLayout(_chatpanelLayout);
        _chatpanelLayout.setHorizontalGroup(
            _chatpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, _chatpanelLayout.createSequentialGroup()
                .addComponent(_chatbox, javax.swing.GroupLayout.DEFAULT_SIZE, 595, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(_sendchat, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE)
        );
        _chatpanelLayout.setVerticalGroup(
            _chatpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(_chatpanelLayout.createSequentialGroup()
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addGroup(_chatpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(_chatbox, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(_sendchat, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        _gamemenu.setText(bundle.getString("GamePlayFrame._gamemenu.text")); // NOI18N
        _gamemenu.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));

        _loaddeck.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        _loaddeck.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        _loaddeck.setText(bundle.getString("GamePlayFrame._loaddeck.text")); // NOI18N
        _loaddeck.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _loaddeckActionPerformed(evt);
            }
        });
        _gamemenu.add(_loaddeck);

        _opendeckeditor.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_K, java.awt.event.InputEvent.CTRL_MASK));
        _opendeckeditor.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        _opendeckeditor.setText(bundle.getString("GamePlayFrame._opendeckeditor.text")); // NOI18N
        _opendeckeditor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _opendeckeditorActionPerformed(evt);
            }
        });
        _gamemenu.add(_opendeckeditor);

        jMenuBar1.add(_gamemenu);

        jMenu1.setText(bundle.getString("GamePlayFrame.jMenu1.text")); // NOI18N
        jMenu1.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));

        _checkrule.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        _checkrule.setFont(new java.awt.Font("ＭＳ Ｐゴシック", 0, 12));
        _checkrule.setText(bundle.getString("GamePlayFrame._checkrule.text")); // NOI18N
        _checkrule.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                _checkruleActionPerformed(evt);
            }
        });
        jMenu1.add(_checkrule);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(_chatpanel, javax.swing.GroupLayout.DEFAULT_SIZE, 661, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(_oppfieldpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(_myfieldpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane4, 0, 0, Short.MAX_VALUE)
                                    .addComponent(_scroll_mydeck, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jScrollPane5, 0, 0, Short.MAX_VALUE)
                                    .addComponent(_scroll_oppdeck, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE))))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1)
                    .addComponent(_oppfieldpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(_scroll_oppdeck)
                            .addComponent(_scroll_mydeck, javax.swing.GroupLayout.DEFAULT_SIZE, 165, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jScrollPane4, 0, 0, Short.MAX_VALUE)
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)))
                    .addComponent(_myfieldpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addComponent(_chatpanel, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void _loaddeckActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__loaddeckActionPerformed
        loadDeck();
    }//GEN-LAST:event__loaddeckActionPerformed

    private void _opendeckeditorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__opendeckeditorActionPerformed
        openDeckEditor();
}//GEN-LAST:event__opendeckeditorActionPerformed

    private void _playActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__playActionPerformed
        setPlay();
    }//GEN-LAST:event__playActionPerformed

    private void _chatboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__chatboxActionPerformed
        sendChat();
}//GEN-LAST:event__chatboxActionPerformed

    private void _sendchatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__sendchatActionPerformed
        sendChat();
}//GEN-LAST:event__sendchatActionPerformed

    private void _checkruleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__checkruleActionPerformed
        try {
            String url = "http://docs.google.com/View?id=dztqbvp_64gndtdzd8";
            Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
        } catch (IOException ex) {
            Logger.getLogger(DeckEditorWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event__checkruleActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextPane _SCArea;
    private javax.swing.JTextField _chatbox;
    private javax.swing.JPanel _chatpanel;
    private javax.swing.JMenuItem _checkrule;
    private javax.swing.JMenu _gamemenu;
    private javax.swing.JMenuItem _loaddeck;
    private javax.swing.JTextPane _messagebox;
    private javax.swing.JList _mydeck;
    private javax.swing.JList _myfield;
    private javax.swing.JPanel _myfieldpanel;
    private javax.swing.JList _mygrave;
    private javax.swing.JList _myplayevent;
    private javax.swing.JList _myplayspell;
    private javax.swing.JMenuItem _opendeckeditor;
    private javax.swing.JList _oppdeck;
    private javax.swing.JList _oppfield;
    private javax.swing.JPanel _oppfieldpanel;
    private javax.swing.JList _oppgrave;
    private javax.swing.JLabel _phase;
    private javax.swing.JButton _play;
    private javax.swing.JScrollPane _scroll_mydeck;
    private javax.swing.JScrollPane _scroll_mydeck1;
    private javax.swing.JScrollPane _scroll_mydeck2;
    private javax.swing.JScrollPane _scroll_oppdeck;
    private javax.swing.JButton _sendchat;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    // End of variables declaration//GEN-END:variables
}
